﻿Public Class EquipmentExplorer
    Inherits ExplorerTreeList

    Public EquipmentPL As PLBase

    Public Sub New(ByVal aQueryName As String)
        MyBase.New(aQueryName)
    End Sub

    Public Sub New()
        MyBase.New()
    End Sub

    Public Overrides Sub PopulateDetailSection()
        Me.Cursor = Cursors.WaitCursor
        '
        If aGridControl IsNot Nothing Then
            aGridControl.Dispose()
            aGridControl = Nothing
        End If
        '
        Dim guidParent As Guid = Nothing
        Dim guidEnfant As Guid = DirectCast(NodeDataRow(Me.KeyFieldName), Guid)
        Dim frmCaption As String = Nothing
        Dim DescriptionLang As String = "_PRM"

        If AppManager.ApplicationOption.DescriptionColumnIndex = 3 Then
            DescriptionLang = "_ALT"
        Else
            DescriptionLang = "_PRM"
        End If

        'frmCaption = NodeDatarow("Description" & DescriptionLang)

        Select Case FocusedNodeLevel
            Case 0
                If AppManager.ApplicationOption.DescriptionColumnIndex = 3 Then
                    frmCaption = "Liste des équipements"
                Else
                    frmCaption = "Equipment List"
                End If
                ShowAllEquipment()
            Case 1
                If NodeDataRow.Table.Columns.Contains("Description") Then
                    frmCaption = String.Format("{0}", NodeDataRow("Description" & DescriptionLang))
                Else
                    frmCaption = "Description" & DescriptionLang
                End If

                ShowByEquipment(guidEnfant)
            Case Else
        End Select



        '
        'On trouve la form pour effacer les controle dedans et ensuite remettre le bon.
        'Comme ca on change le Detail selon la ligne dans L'explorer
        For Each aFrm As XtraForm In Me.ParentForm.MdiChildren
            If aFrm.Name = PanelName Then
                aFrm.Controls.Clear()
                aFrm.Controls.Add(aGridControl)
                aFrm.Text = frmCaption
                aFrm.Show()
                aFrm.Focus()
            End If
            aFrm.Refresh()
        Next

        Me.Cursor = Cursors.Default
    End Sub

    Public Overridable Sub ShowAllEquipment()
        EquipmentPL = PLBase.CreateInstanceOf(PLTypeOf.Equipment_PL, "Equipment")

        'Scoper nouveau PL en haut en haut        
        aGridControl = New GridExtPL() With {.Dock = DockStyle.Fill, .Pl = EquipmentPL, .SecureGrid = True, .Name = "Equipment List", .FormCtrlCD = PanelName}
        AddHandler aGridControl.InitNewMasterRow, AddressOf Equipment_InitNewMasterRow

        aGridControl.GridActionOptionList.Add(New ActionOption("Equipment", "ACT_00189", "Create Equipment To Product", AddressOf Equipment_SaveToProduct, True, True))
    End Sub

    Public Overridable Sub ShowByEquipment(ByVal EquipmentID As System.Guid)
        EquipmentPL = PLBase.CreateInstanceOf(PLTypeOf.Equipment_PL, "Equipment")

        'Scoper nouveau PL en haut en haut        
        aGridControl = New GridExtPL() With {.Dock = DockStyle.Fill, .Pl = EquipmentPL, .SecureGrid = True, .Name = "Equiment List", .FormCtrlCD = MyBase.PanelName}
        EquipmentPL.SQLWhere = String.Format("EquipmentID = '{0}'", EquipmentID)
        AddHandler aGridControl.InitNewMasterRow, AddressOf Equipment_InitNewMasterRow

        aGridControl.GridActionOptionList.Add(New ActionOption("Equipment", "ACT_00189", "Create Equipment To Product", AddressOf Equipment_SaveToProduct, True, True))

    End Sub

End Class
